home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / syslog.c < prev    next >
C/C++ Source or Header  |  1994-02-26  |  7KB  |  193 lines

  1. RCS_ID_C="$Id: syslog.c,v 3.3 1994/02/26 17:57:21 jraja Exp $";
  2. /*
  3.  * syslog.c --- syslog function stubs for the AmiTCP/IP
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      : Sat Jan 22 12:19:02 1994 jraja
  12.  * Last modified: Sat Feb 26 19:52:42 1994 jraja
  13.  *
  14.  */
  15.  
  16. #include <sys/param.h>
  17. #include <sys/syslog.h>
  18.  
  19. #include <bsdsocket.h>
  20. #include <amitcp/socketbasetags.h>
  21.  
  22. /****** net.lib/syslog *********************************************
  23. *
  24. *   NAME   
  25. *       openlog(), closelog(), setlogmask() -- syslog utility functions
  26. *
  27. *   SYNOPSIS
  28. *       #include <syslog.h>
  29. *       
  30. *       openlog(ident, logopt, facility);
  31. *
  32. *       void openlog(const char *, int, int);
  33. *
  34. *       closelog();
  35. *
  36. *       void closelog(void);
  37. *
  38. *       oldmask = setlogmask(maskpri);
  39. *       
  40. *       int setlogmask(int);
  41. *       
  42. *   FUNCTION
  43. *       openlog() can be called to initialize the log file, if special
  44. *       processing is needed.  ident is a string that precedes every
  45. *       message.  logopt is a mask of bits, logically OR'ed together,
  46. *       indicating logging options.  The values for logopt are:
  47. *       
  48. *            LOG_PID             Log the process ID with each message;
  49. *                                useful for identifying instantiations
  50. *                                of daemons.
  51. *
  52. *            LOG_CONS            Force writing messages to the console
  53. *                                if unable to send it to syslogd.
  54. *                                This option is safe to use in daemon
  55. *                                processes that have no controlling
  56. *                                terminal because syslog() forks
  57. *                                before opening the console.
  58. *
  59. *            LOG_NDELAY          Open the connection to syslogd
  60. *                                immediately.  Normally, the open is
  61. *                                delayed until the first message is
  62. *                                logged.  This is useful for programs
  63. *                                that need to manage the order in
  64. *                                which file descriptors are allocated.
  65. *
  66. *            LOG_NOWAIT          Do not wait for children forked to
  67. *                                log messages on the console. Obsolete
  68. *                                in AmiTCP/IP, since AmiTCP/IP does
  69. *                                not fork.
  70. *
  71. *       facility encodes a default facility to be assigned to all
  72. *       messages written subsequently by syslog() with no explicit
  73. *       facility encoded. The facility codes are:
  74. *
  75. *            LOG_KERN            Messages generated by the kernel.
  76. *                                These cannot be generated by any user
  77. *                                processes.
  78. *
  79. *            LOG_USER            Messages generated by random user
  80. *                                processes.  This is the default
  81. *                                facility identifier if none is
  82. *                                specified.
  83. *
  84. *            LOG_MAIL            The mail system.
  85. *
  86. *            LOG_DAEMON          System daemons, such as inetd, ftpd,
  87. *                                etc.
  88. *
  89. *            LOG_AUTH            The authorization system: login, su,
  90. *                                getty, etc.
  91. *
  92. *            LOG_LPR             The line printer spooling system: lp,
  93. *                                lpsched, etc.
  94. *
  95. *            LOG_LOCAL0          Reserved for local use. Similarly for
  96. *                                LOG_LOCAL1 through LOG_LOCAL7.
  97. *
  98. *
  99. *       closelog() closes the log file.
  100. *
  101. *       setlogmask() sets the log priority mask to maskpri and returns
  102. *       the previous mask.  Calls to syslog() with a priority not set
  103. *       in maskpri are rejected.  The mask for an individual priority
  104. *       pri is calculated by the macro LOG_MASK(pri); the mask for all
  105. *       priorities up to and including toppri is given by the macro
  106. *       LOG_UPTO(toppri).  By default, all priorities are logged.
  107. *
  108. *   EXAMPLES
  109. *       who logs a message regarding some sort of unexpected and
  110. *       serious error:
  111. *
  112. *           syslog(LOG_ALERT, "who: internal error 23");
  113. *
  114. *       ftpd uses openlog() to arrange to log its process ID, to log
  115. *       to the console if necessary, and to log in the name of the
  116. *       daemon facility:
  117. *
  118. *           openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
  119. *
  120. *       Arrange to log messages only at levels LOG_ERR and lower:
  121. *
  122. *           setlogmask(LOG_UPTO(LOG_ERR));
  123. *
  124. *       Typical usage of syslog() to log a connection:
  125. *
  126. *           syslog(LOG_INFO, "Connection from host %d", CallingHost);
  127. *
  128. *       If the facility has not been set with openlog(), it defaults
  129. *       to LOG_USER.
  130. *
  131. *       Explicitly set the facility for this message:
  132. *
  133. *           syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
  134. *       
  135. *   NOTES
  136. *       openlog() does not copy and store the ident string internally;
  137. *       it stores only the character pointer.  Therefore it is the
  138. *       responsibility of the programmer to make sure that the ident
  139. *       argument points to the correct string while syslog() is being
  140. *       called. 
  141. *
  142. *   BUGS
  143. *       Most of the logopt and facility codes are currently being
  144. *       ignored by AmiTCP/IP, but they should be used for future
  145. *       compatibility.
  146. *
  147. *       The autoinit module of the net.lib tells the program name 
  148. *       to the AmiTCP/IP at program startup, so use of the openlog()
  149. *       for that purpose only is not necessary.
  150. *
  151. *   AUTHOR
  152. *       syslog() was developed by the University of California,
  153. *       Berkeley.
  154. *
  155. *   SEE ALSO
  156. *       bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
  157. *****************************************************************************
  158. *
  159. */
  160. void
  161. openlog(const char *ident, int logstat, int logfac)
  162. {
  163.   /*
  164.    * Note: SocketBaseTags() does value checking for the arguments
  165.    */
  166.   SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR), ident,
  167.          SBTM_SETVAL(SBTC_LOGSTAT), logstat,
  168.          SBTM_SETVAL(SBTC_LOGFACILITY), logfac,
  169.          TAG_END);
  170. }
  171.  
  172. void
  173. closelog(void)
  174. {
  175.   SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR), NULL,
  176.          TAG_END);
  177. }
  178.  
  179. /* setlogmask -- set the log mask level */
  180. int
  181. setlogmask(int pmask)
  182. {
  183.   ULONG taglist[5];
  184.  
  185.   taglist[0] = SBTM_GETVAL(SBTC_LOGMASK);
  186.   taglist[2] = SBTM_SETVAL(SBTC_LOGMASK);
  187.   taglist[3] = pmask;
  188.   taglist[4] = TAG_END;
  189.  
  190.   SocketBaseTagList((struct TagItem *)taglist);
  191.   return (int)taglist[1];
  192. }
  193.